Skip to content

Allow passing pathlib.PosixPath to the function read_from_text_file()#787

Draft
xingularity wants to merge 1 commit into
solvcon:masterfrom
xingularity:hotfix/handle-posix-path-issue-786
Draft

Allow passing pathlib.PosixPath to the function read_from_text_file()#787
xingularity wants to merge 1 commit into
solvcon:masterfrom
xingularity:hotfix/handle-posix-path-issue-786

Conversation

@xingularity
Copy link
Copy Markdown

@xingularity xingularity commented May 17, 2026

Modified if statement in modmesh/track/dataframe. This is to handle file name as a PosixPath instance.

This is for issue #786.

@xingularity xingularity marked this pull request as draft May 21, 2026 07:04
@xingularity xingularity force-pushed the hotfix/handle-posix-path-issue-786 branch from a8ab00b to 9930fd0 Compare May 23, 2026 05:01
@xingularity xingularity marked this pull request as ready for review May 23, 2026 09:35
@tigercosmos
Copy link
Copy Markdown
Member

Sorry maybe I didn't fully understand the test cases. I wonder are the test cases be able to catch the errors that happens in #786?

@xingularity
Copy link
Copy Markdown
Author

xingularity commented May 23, 2026

Sorry maybe I didn't fully understand the test cases. I wonder are the test cases be able to catch the errors that happens in #786?

Yes, test case test_read_from_text_file_accepts_pathlib_path is for it. The pathlib.Path function call is going to generate a pathlib.PosixPath instance under linux.

@yungyuc yungyuc changed the title Fixed issue-786 Allow passing pathlib.PosixPath to the function read_from_text_file() May 23, 2026
@yungyuc yungyuc added the array Multi-dimensional array implementation label May 23, 2026
@yungyuc yungyuc moved this to In Progress in tabular data processing May 23, 2026
@yungyuc
Copy link
Copy Markdown
Member

yungyuc commented May 23, 2026

I changed the subject to be more informative.

Copy link
Copy Markdown
Member

@yungyuc yungyuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave inline annotations in the PR. The fix itself is simple, but the unit tests are not trivial. Also leave a global comment to request for review.

See the PR protocol in issue #811 .

@xingularity
Copy link
Copy Markdown
Author

Please leave inline annotations in the PR. The fix itself is simple, but the unit tests are not trivial. Also leave a global comment to request for review.

See the PR protocol in issue #811 .

@yungyuc and @tigercosmos The comment has been added, you can review now.

Copy link
Copy Markdown
Member

@yungyuc yungyuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Use inline annotation for discussions in the PR, not code comments.
  • Also check for error messages, not just the exception type.

Comment thread tests/test_timeseries_dataframe.py Outdated
finally:
os.unlink(path)

# Theis test is for a bug reported in issue #786:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that you misunderstood what we meant by inline annotations. In #787 (review), "inline annotations in the PR" is like the inline comment I am leaving here. It is not code remarks/comments.

Please remove the unnecessary code comments and turn it into a PR inline annotation.

Copy link
Copy Markdown
Member

@tigercosmos tigercosmos May 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: there is a typo Theis.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is for a bug reported in issue #786: #786

If user uses time series DataFrame under Linux, it is likely to be given a pathlib.PosixPath instance to be the path to text file. This test is to make sure DataFrame support a path (frame) which is from pathlib.

nd_arr = np.genfromtxt(io.StringIO(self.dlc_data), delimiter=',')[1:]
self.assertEqual(list(col_data), list(nd_arr[:, 1]))

def test_read_from_text_file_accepts_str_path(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look like related to the fix. Please share with us why do you want to include it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file path can be either a string or a os.PathLike instance. This test is added is to explicitly test if the DataFrame can accept str type text file path.

Comment thread tests/test_timeseries_dataframe.py Outdated
def test_read_from_text_file_missing_raises_filenotfound(self):
tsdf = dataframe.DataFrame()
missing = pathlib.Path(tempfile.gettempdir()) / 'no_such_file.csv'
with self.assertRaises(FileNotFoundError):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also check for error messages, not just the exception type.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in the commit f13f83d

@xingularity xingularity force-pushed the hotfix/handle-posix-path-issue-786 branch 2 times, most recently from 35bac1d to 114f43d Compare May 30, 2026 08:32
@xingularity xingularity marked this pull request as draft May 31, 2026 05:28
@xingularity xingularity force-pushed the hotfix/handle-posix-path-issue-786 branch from 114f43d to 0235bf6 Compare May 31, 2026 06:26
1. Modify DataFrame code to accept os.PathLike csv paths.
2. Add tests to explicitly test if dataframe can accept paths from
   `pathlib` as well as a string
3. Enhance the exception raise to explicitly indicates the files are not
   found.
4. Add tests to test raised Exception type as well as the error message.
@xingularity xingularity force-pushed the hotfix/handle-posix-path-issue-786 branch from 0235bf6 to 16c80aa Compare May 31, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

array Multi-dimensional array implementation

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants